<div class="content blog">
    <ul class="breadcrumb">
        <li><a href="index.php?r=blog">博客管理</a></li>
        <li class="active">创建博客</li>
    </ul>
    <div class="row-fluid">
        <div class="page-header">
            <h2>创建博客</h2>
        </div>
        <div class="input-group">
            <span class="input-group-addon" id="basic-addon1">标题</span>
            <input type="hidden" id="id" value="<?php if(isset($ret)) { echo $ret['aid'];}?>"/>
            <input type="text" id="title" class="form-control" placeholder="博客标题" aria-describedby="basic-addon1" value="<?php if(isset($ret)) { echo $ret['title'];}?>"/>
        </div>
        <div style="margin-top:20px;">
            <textarea id="context" class="ckeditor" name="context"><?php if(isset($ret)) { echo $ret['content'];}?></textarea>
<!--            <script id="context" name="content" type="text/plain" style="height:400px">
                <?php if(isset($ret)) { echo $ret['content'];}?>
            </script>-->
        </div>
        <div style="margin:20px 0px;">
            <button class="btn btn-success blogsave"><i class="glyphicon glyphicon-ok"></i>保存</button>
        </div>
    </div>
</div>
<script src="//cdn.ckeditor.com/4.5.2/full/ckeditor.js"></script>
<link rel="stylesheet" href="../../vendor/libs/highlight/styles/tomorrow-night.css">
<script src="../../vendor/libs/highlight/highlight.pack.js"></script>
<!--<script type="text/javascript" src="../../vendor/libs/ueditor1_4_3/ueditor.config.js"></script>-->
<!-- 编辑器源码文件 -->
<!--<script type="text/javascript" src="../../vendor/libs/ueditor1_4_3/ueditor.all.js"></script>-->
<!-- 实例化编辑器 -->
<script type="text/javascript">
    $(document).ready(function() {
        //var editor = UE.getEditor('context');
        hljs.initHighlightingOnLoad();
        CKEDITOR.replace( 'context' );
        CKEDITOR.plugins.add( 'myCustomHighlighter', {
            afterInit: function( editor ) {
                // Create a new instance of the highlighter.
                var myHighlighter = new CKEDITOR.plugins.codesnippet.highlighter( {
                    init: function( ready ) {
                        // Asynchronous code to load resources and libraries for customEngine.
                        customEngine.loadResources( function() {
                            // Let the editor know that everything is ready.
                            ready();
                        } );
                    },
                    highlighter: function( code, language, callback ) {
                        // Let the customEngine highlight the code.
                        customEngine.highlight( code, language, function() {
                            callback( highlightedCode );
                        } );
                    }
                } );

                // Check how it performs.
                myHighlighter.highlight( 'foo()', 'javascript', function( highlightedCode ) {
                    console.log( highlightedCode ); // -> <span class="pretty">foo()</span>
                } );

                // From now on, myHighlighter will be used as a Code Snippet
                // highlighter, overwriting the default engine.
                editor.plugins.codesnippet.setHighlighter( myHighlighter );
            }
        } );
        $(".blogsave").on('click',function() {
            var id = $("#id").val();
            var title = $('#title').val();
            //var ct = editor.getContent();
            var ct = CKEDITOR.instances.context.getData();
            $.ajax({
                type : 'POST',
                url : 'index.php?r=blog/add',
                dataType : 'json',
                async: false,
                data : {
                    id : id,
                    title: title,
                    content: ct
                },
                success : function(resJson, textStatus){
                    alert("恭喜，提交成功！");
                    //window.location.href="index.php?r=blog";
                }
            });
        });
    });

</script>
